<?php

namespace App\Http\Controllers;

use App\Http\Resources\AreaCollection;
use App\Http\Resources\FactoryRentNatureCollection;
use App\Http\Resources\FactoryRentTypeCollection;
use App\Http\Resources\PriceCollection;
use App\Models\Area;
use App\Models\FactoryRentNature;
use App\Models\FactoryRentType;
use App\Models\RentPrice;
use Illuminate\Http\Request;

class FilterController extends Controller
{
    public function price(Request $request)
    {
        $type = $request->input('type');
        $price = RentPrice::when($type, function ($query) use ($type) {
            $query->where('type', $type);
        })->get();
        return new PriceCollection($price);
    }

    public function area(Request $request)
    {
        $type = $request->input('type');
        $area = Area::when($type, function ($query) use ($type) {
            $query->where('type', $type);
        })->get();
        return new AreaCollection($area);
    }

    public function type(Request $request)
    {
        $type = $request->input('type');
        $rentType = FactoryRentType::when($type, function ($query) use ($type) {
            $query->where('type', $type);
        })->get();
        return new FactoryRentTypeCollection($rentType);
    }

    public function nature(Request $request)
    {
        $type = $request->input('type');
        $nature = FactoryRentNature::when($type, function ($query) use ($type) {
            $query->where('type', $type);
        })->get();
        return new FactoryRentNatureCollection($nature);
    }
}
